package com.lovemanai.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.lovemanai.service.Being;
import com.lovemanai.service.Person;

public class Demo1 {
	
	/**
	 * 静态工厂方法创建bean
	 */
	@Test
	public void test1() {
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		
		Being b1 = ctx.getBean("dog", Being.class);
		b1.testBeing();
		Being b2 = ctx.getBean("cat", Being.class);
		b2.testBeing();
		
	}
	
	/**
	 * 动态工厂方法创建bean
	 */
	@Test
	public void test2() {
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		Person p1 = ctx.getBean("chinese", Person.class);
		System.out.println(p1.sayGoodBye("小乔"));
		
		
	}
	
	/**
	 * 使用容器中的工厂bean
	 */
	@Test
	public void test3() {
		
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		System.out.println(ctx.getBean("north"));
		System.out.println(ctx.getBean("theValue"));
		System.out.println(ctx.getBean("&theValue"));//获取地址
	}
}
